<style>
	.table4_7 table {
		width: 100%;
		margin: 15px 0;
		border: 0;
	}
	
	.table4_7 th {
		background-color: #00A5FF;
		color: #FFFFFF
	}
	
	.table4_7,
	.table4_7 th,
	.table4_7 td {
		font-size: 0.95em;
		text-align: center;
		padding: 8px;
		padding-left: 10px;
		padding-right: 30px;
		border-collapse: collapse;
	}
	
	.table4_7 th,
	.table4_7 td {
		border: 1px solid #6dcbfe;
		border-width: 1px 0 1px 0
	}
	
	.table4_7 tr {
		border: 1px solid #6dcbfe;
	}
	
	.table4_7 tr:nth-child(odd) {
		background-color: #aae1fe;
	}
	
	.table4_7 tr:nth-child(even) {
		background-color: #fdfdfd;
	}
	table,form{
		margin-left: 10%;
	}
</style>

<form action="/houtai.php?ctr=jie" method="post">
	<input type="text" placeholder="用户查找。。" name="user" style="width: 510px;height: 30px;margin-bottom:5px ;"/>
	<input type="submit" value="查找" style="height: 33px;width: 70px;"/>
</form>
<?php 
	require_once "app/conn.php";
	
	//删除记录
	if(!empty($_GET['del'])){
		$sql="DELETE FROM jie WHERE 借阅编号=".$_GET['del'];
		$conn->query($sql);
	}
	
	
	//还书
	if(!empty($_GET['huan'])){
		
		$sql="select * from book where id=".$_GET['book_id'];
		$result = $conn->query($sql);
		$row=mysqli_fetch_assoc( $result );
		$num=$row["数量"]+1;
		$sql="update book set 数量=".$num." where id=".$_GET['book_id'];
		$conn->query($sql);
//		if ($conn->query($sql) === TRUE) {
// 	 	echo "数量更新成功";
// 	 	echo $num;
//		} else {
// 		 echo "Error: " . $sql . "<br>" . $conn->error;
//		}
		
		$t=time();
		$now_time=date("Y-m-d",$t);
		$sql="update jie set 还书时间='".$now_time."' where 借阅编号=".$_GET['huan'];
		$conn->query($sql);
	}
	
	
	?>
<table class=table4_7>
	<tr>
		<th>借阅编号</th>
		<th>借书时间</th>
		<th>还书时间</th>
		<th>图书名称</th>
		<th>用户名</th>
		<th>操作</th>
	</tr>
	<?php 
		
		//list
		$sql="select * from jie";
		$result = $conn->query($sql);
		while($row = mysqli_fetch_assoc( $result )){
		?>
	<tr>
		<td><?PHP echo $row["借阅编号"]?></td>
		<td><?PHP echo $row["借书时间"]?></td>
		<td><?PHP echo $row["还书时间"]?></td>
		<td><?PHP 
			$sql1="select * from book where id=".$row["图书编号"];
			$result1 = $conn->query($sql1);
			$row1=mysqli_fetch_assoc( $result1 );
			echo $row1['书名'];
			?></td>
		<td><?PHP
			$sql1="select * from users where id=".$row["用户编号"];
			$result1 = $conn->query($sql1);
			$row1=mysqli_fetch_assoc( $result1 );
			echo $row1['账号'];
			?></td>
		<td><!--<a href="/houtai.php?ctr=jie&huan=<?PHP echo $row["借阅编号"]?>">还书</a>-->
			<?php
			if(empty($row["还书时间"]))
			{
				echo '<a href="/houtai.php?ctr=jie&huan='.$row["借阅编号"].'&book_id='.$row["图书编号"].'">还书</a>';
			}else
			{
				echo '<a href="/houtai.php?ctr=jie&del='.$row["借阅编号"].'">删除</a>';
			}
			?>
		</td>
		
		
	</tr>
	
	<?php }?>
</table>